﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.Utilities;
using CuaHangMayTinh.DataProvider;
using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.DataAccessLayer;
using System.Data;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    public class SubGroupUserManager
    {
        private static SubGroupUserDA adapter = null;

        static SubGroupUserManager()
        {
            if (adapter == null)
                adapter = new SubGroupUserDA();
        }
        /// <summary>
        /// Hàm thêm 1 SubGroupUserEntity mới
        /// </summary>
        /// <param name="entity">SubGroupUserEntity muốn thêm mới</param>
        /// <returns>0: thất bại, 1: thành công</returns>
        public static int Insert(SubGroupUserEntity entity)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm thêm 1 SubGroupUserEntity mới
        /// </summary>
        /// <param name="entity">SubGroupUserEntity muốn thêm mới</param>
        /// <param name="errormessage">Trả về lỗi nếu có</param>
        /// <returns>0: thất bại, 1: thành công</returns>
        public static int Insert(SubGroupUserEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm thêm 1 SubGroupUserEntity mới, trả về ID mới thêm vào
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int InsertGetID(SubGroupUserEntity entity)
        {
            try
            {
                return adapter.InsertGetID(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int InsertGetID(SubGroupUserEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.InsertGetID(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm Cập nhật 1 SubGroupUserEntity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool UpDate(SubGroupUserEntity entity)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool UpDate(SubGroupUserEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm tìm tất cả SubGroupUserEntity
        /// </summary>
        /// <returns></returns>
        public static DataTable Find_All()
        {
            try
            {
                return adapter.Find_All();
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_All(ref string errormessage)
        {
            try
            {
                return adapter.Find_All();
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm tìm SubGroupUserEntity bằng ID
        /// </summary>
        /// <param name="IDSubGroupUser"></param>
        /// <returns></returns>
        public static DataTable Find_ID(int IDSubGroupUser)
        {
            try
            {
                return adapter.Find_ID(IDSubGroupUser);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDSubGroupUser"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_ID(int IDSubGroupUser, ref string errormessage)
        {
            try
            {
                return adapter.Find_ID(IDSubGroupUser);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm tìm SubGroupUser bằng ID của GroupUser
        /// </summary>
        /// <param name="IDGroupUser"></param>
        /// <returns></returns>
        public static DataTable Find_IDGroupUser(int IDGroupUser)
        {
            try
            {
                return adapter.Find_IDGroupUser(IDGroupUser);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDGroupUser"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_IDGroupUser(int IDGroupUser, ref string errormessage)
        {
            try
            {
                return adapter.Find_IDGroupUser(IDGroupUser);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm tìm SubGroupUser bằng tên
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public static DataTable Find_Ten(string Name)
        {
            try
            {
                return adapter.Find_Ten(Name);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_Ten(string Name, ref string errormessage)
        {
            try
            {
                return adapter.Find_Ten(Name);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm tìm ID của 1 SubGroupUser
        /// </summary>
        /// <param name="name">Tên của SubGroupUser</param>
        /// <returns></returns>
        public static int GetID(string Name)
        {
            try
            {
                return adapter.GetID(Name);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int GetID(string Name, ref string errormessage)
        {
            try
            {
                return adapter.GetID(Name);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }


        /// <summary>
        /// Hàm xóa 1 SubGroupUser
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool Delete(int id)
        {
            try
            {
                return adapter.Delete(id);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool Delete(int id, ref string errormessage)
        {
            try
            {
                return adapter.Delete(id);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List<SubGroupUserEntity> ConvertToList(DataTable dt)
        {
            try
            {
                return adapter.ConvertToList(dt);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }
    }
}